package module.map.nodes
{
	import drongo.model.events.ModelEvent;
	import drongo.model.propertys.NumberProperty;
	
	import flash.filesystem.File;
	
	import module.map.model.Propertys;
	
	import ui.Map.UI_TowerNodeView;

	public class TowerNodeMediator extends BaseNodeMediator
	{
		[Inject]
		public var view:UI_TowerNodeView;
		public function TowerNodeMediator()
		{
			super();
		}
		
		override public function initialize():void{
			super.initialize();
			this.Init(this.view);
			this.RefreshView();
		}
		
		private function RefreshView():void{
			this.view.x=this.nodeData.Get(Propertys.X).GetValue();
			this.view.y=this.nodeData.Get(Propertys.Y).GetValue();
			this.view.visible=this.nodeData.Get(Propertys.VISIBLE).GetValue()==1;
			this.view.touchable=this.nodeData.Get(Propertys.LOCK).GetValue()==0;
			if(this.nodeData.Get(Propertys.TOWER_TYPE)==null)
			{
				this.nodeData.Add(new NumberProperty(Propertys.TOWER_TYPE,0));
			}
			this.view.m_c1.selectedIndex=this.nodeData.Get(Propertys.TOWER_TYPE).GetValue();
		}
		
		override protected function AddEvents():void{
			super.AddEvents();
			this.nodeData.addEventListener(ModelEvent.CHILD_VALUE_CHANGED,this.PropertyUpdateHandler);
		}
		
		override protected function RemoveEvents():void{
			super.RemoveEvents();
			this.nodeData.removeEventListener(ModelEvent.CHILD_VALUE_CHANGED,this.PropertyUpdateHandler);
		}
		
		private function PropertyUpdateHandler(e:ModelEvent):void{
			this.RefreshView();
		}
	}
}